package com.jspgou.cms.dao.impl;

import org.springframework.stereotype.Repository;

import com.jspgou.common.hibernate3.Finder;
import com.jspgou.common.hibernate3.HibernateBaseDao;
import com.jspgou.common.page.Pagination;
import com.jspgou.cms.dao.AftersaleDao;
import com.jspgou.cms.entity.Aftersale;

@Repository
public class AftersaleDaoImpl extends HibernateBaseDao<Aftersale, Long>
     implements AftersaleDao {
	
	public Pagination getPage(Long memberId,Long storeId,Long typeId,Long demandId,
			int pageNo, int pageSize){
		Finder f=Finder.create("from Aftersale bean where 1=1");
		if(memberId!=null){
			f.append(" and bean.member.id=:memberId");
			f.setParam("memberId", memberId);
		}
		if(storeId!=null){
			f.append(" and bean.store.id=:storeId");
			f.setParam("storeId", storeId);
		}
		if(typeId!=null){
			f.append(" and bean.type.id=:typeId");
			f.setParam("typeId", typeId);
		}
		if(demandId!=null){
			f.append(" and bean.demand.id=:demandId");
			f.setParam("demandId", demandId);
		}
		f.append(" order by bean.applyTime desc");
		return find(f, pageNo, pageSize);
	}

	public Aftersale findById(Long id) {
		Aftersale entity = get(id);
		return entity;
	}

	public Aftersale save(Aftersale bean) {
		getSession().save(bean);
		return bean;
	}

	public Aftersale deleteById(Long id) {
		Aftersale entity = super.get(id);
		if (entity != null) {
			getSession().delete(entity);
		}
		return entity;
	}
	
	@Override
	protected Class<Aftersale> getEntityClass() {
		return Aftersale.class;
	}
}